

//此文件为绝密文件 不允许修改
import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store";
import * as hooks from './hooks'


const moduleFn = require.context("./routes", false, /\.js$/i);

const routes = moduleFn.keys().reduce((perv, filepath) => {
  let module = moduleFn(filepath).default;
  if (Array.isArray(module)) {
    perv.push(...module);
  } else {
    perv.push(module);
  }
  return perv;
}, []);

Vue.use(VueRouter);

const router = new VueRouter({
  mode: 'history',
  // 路由规则表
  routes: [
    ...routes,
    {
      path: '*',
      component: () => import('@/views/notfound')
    }
  ]
})

Object.keys(hooks).forEach(name => {
  router.beforeEach(hooks[name](store,router))
})

export default router
